package me.sealer.config;

import me.sealer.controller.FunctionController;
import me.sealer.service.FunctionService;
import org.springframework.context.annotation.*;

/**
 * Created by sealer on 09-09-2017.
 */
@Configuration
/*@ComponentScans({@ComponentScan("me.sealer.aop"), @ComponentScan("me.sealer.controller"), @ComponentScan("me.sealer.service")})*/
/*@ComponentScan("me.sealer.aop")*/
@ComponentScans({@ComponentScan("me.sealer.aop"), @ComponentScan("me.sealer.event.listener"), @ComponentScan("me.sealer.event.publisher"), @ComponentScan("me.sealer")})
@EnableAspectJAutoProxy
public class BeanConfig {
    @Bean(initMethod = "initDev", destroyMethod = "destroyDev")
    @Profile("dev")
    public FunctionService devFunctionService() {
        return new FunctionService();
    }

    @Bean(initMethod = "initProd", destroyMethod = "destroyProd")
    @Profile("prod")
    public FunctionService prodFunctionService() {
        return new FunctionService();
    }

    @Bean
    @Profile("dev")
    public FunctionController devFunctionController() {
        FunctionController functionController = new FunctionController();
        functionController.setFunctionService(devFunctionService());
        return functionController;
    }

    @Bean
    @Profile("prod")
    public FunctionController prodFunctionController() {
        FunctionController functionController = new FunctionController();
        functionController.setFunctionService(prodFunctionService());
        return functionController;
    }
}
